package cn.huijielong.modules.oss.cloud;

import cn.huijielong.common.utils.SpringContextUtils;
import cn.huijielong.common.validator.Assert;
import cn.huijielong.modules.oss.entity.Oss;
import cn.huijielong.modules.oss.service.SysOssService;

/**
 * 文件上传Factory
 */
public final class OSSFactory {
	private static SysOssService sysOssService;

    static {
        OSSFactory.sysOssService = (SysOssService) SpringContextUtils.getBean("sysOssService");
    }

    public static CloudStorage build(String ossName,String bucketName){
        //获取云存储配置信息
    	OSSConfig config = sysOssService.getOSSConfig();
    	Oss oss=config.getOss(ossName);
    	Assert.isNull(oss, ossName+" 对应的配置为空");
    		
        if(oss.getName().equals("ali"))
        	return new AliyunCloudStorage(oss, bucketName);
        else if(oss.getName().equals("tx"))
        	return new QcloudCloudStorage(oss, bucketName);
        else if(oss.getName().equals("qiniu"))
        	return new QiniuCloudStorage(oss, bucketName);
        return null;
    }
}
